﻿/*
 * 版 本 v1.0
 * Copyright (c) 2013-2018 广州市同慧信息科技有限公司
 * 创建人：ftquan
 * 日 期：2017.03.22
 * 描 述：令牌管理
 */
var selectedRow;
var refreshGirdData;
var bootstrap = function ($, learun) {
    "use strict";
    var page = {
        init: function () {
            page.initGrid();
            page.bind();
        },
        bind: function () {
            // 查询
            $('#btn_Search').on('click', function () {
                var keyword = $('#txt_Keyword').val();
                page.search({keyword: keyword});
            });
            // 刷新
            $('#lr_refresh').on('click', function () {
                location.reload();
            });
            // 删除
            $('#lr_delete').on('click', function () {
                var keyValue = $('#gridtable').jfGridValue('token_value');
                if (learun.checkrow(keyValue)) {
                    learun.layerConfirm('该动作执行后此项将彻底被删除，是否确认删除该项?', function (res) {
                        if (res) {
                            learun.deleteForm(config.base_server() + 'oauth/remove/token?access_token=' + config.getToken().access_token, {keyValue: keyValue}, function () {
                                refreshGirdData();
                            });
                        }
                    });
                }
            });
        },
        initGrid: function () {
            $('#gridtable').jfGrid({
                url: config.base_server() + 'oauth/token/list?access_token=' + config.getToken().access_token,
                headData: [
                    {label: '用户编号', name: 'user_id', width: 100, align: 'left'},
                    {label: '用户名称', name: 'user_name', width: 200, align: 'left'},
                    {label: '应用ID', name: 'client_id', width: 130, align: 'center'},
                    {label: '类型', name: 'token_type', width: 130, align: 'center'},
                    {label: 'token', name: 'token_value', width: 130, align: 'center'},
                    {label: '授权方式', name: 'grant_type', width: 130, align: 'center'},
                    {label: '用户头像', name: 'user_head_imgurl', width: 130, align: 'center'}
                ],
                isPage: true,
                reloadSelected: true,
                mainId: 'id'
            });

            page.search();
        },
        search: function (param) {
            param = param || {};
            $('#gridtable').jfGridSet('reload', param);
        }
    };

    refreshGirdData = function () {
        page.search();
    };

    page.init();
}


